import request from "@/utils/request.js";

const PREFIX = '/user/cartItem'

// 加入购物车
export const addCartItem = async (productId) => {
    return await request.post(`${PREFIX}/${productId}`)
}

// 获取购物车列表
export const getCartItems = async () => {
    return await request.get(PREFIX)
}

// 获取结算商品信息
export const getCheckout = async (cartItemIds) => {
    return await request.post(`${PREFIX}/checkout`, {
        ids: cartItemIds
    })
}


// 更新购物车商品数量
export const updateCartItemQuantity = async (id, quantity) => {
    return await request.put(`${PREFIX}/${id}/${quantity}`)
}

// 更新购物车商品选中状态
export const updateCartItemSelected = async (id, selected) => {
    return await request.put(`${PREFIX}/${id}`, {
        selected: Number(selected)
    })
}

// 更新购物车所有商品选中状态
export const updateAllCartSelected = async (selected) => {
    return await request.put(`${PREFIX}/all/${Number(selected)}`)
}
// 删除购物车商品
export const removeCartItem = async (id) => {
    return await request.delete(`${PREFIX}/${id}`,)
}
